package com.nsoft.remoteserver;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import com.nsoft.remoteserver.utils.Constant;
import com.nsoft.remoteserver.utils.Utils;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;



public class RemotePlayer extends JFrame {
	
	private static final long serialVersionUID = 1L;
	private JButton refreshBtn;
	
	public RemotePlayer(String title){
		super(title);
		
		try{
            UIManager.setLookAndFeel(new WindowsLookAndFeel());
            SwingUtilities.updateComponentTreeUI(this);
		}catch(Exception ex){ }
		
        SwingUtilities.invokeLater(new Runnable(){
            public void run(){
            	createGUI();
            }
        });
        

	}
	
	private void createGUI(){
		Container mainContainer=getContentPane();
		mainContainer.setLayout(new BorderLayout());
		
		JToolBar mainTBar=new JToolBar(JToolBar.HORIZONTAL);
		
		ImageIcon refreshIcon=Utils.createImageIcon(
					Constant.ui.TBAR_BUTTON_REFRESH);
		refreshBtn=new JButton(
				Constant.ui.TBAR_BUTTON_REFRESH,
				refreshIcon);
		refreshBtn.setBorder(BorderFactory.createEmptyBorder());
		mainTBar.add(refreshBtn);
		ImageIcon exitIcon=Utils.createImageIcon(
				Constant.ui.TBAR_BUTTON_EXIT);
		JButton exitBtn=new JButton(
				Constant.ui.TBAR_BUTTON_EXIT,
				exitIcon);
		exitBtn.setBorder(BorderFactory.createEmptyBorder());
		mainTBar.add(exitBtn);
		exitBtn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				
			}
		});
		
		mainContainer.add(mainTBar,BorderLayout.NORTH);
		
		JTabbedPane mainTabs=new JTabbedPane();
		
		ImageIcon u2bIcon=Utils.createImageIcon(
					Constant.ui.TAB_VIDEOS);
		mainTabs.addTab(Constant.ui.TAB_VIDEOS,u2bIcon,
						new VideoPlayerPanel(),
						Constant.ui.TAB_U2B_DESC);
		mainTabs.setMnemonicAt(0,KeyEvent.VK_1);

		ImageIcon settingsIcon=Utils.createImageIcon(
					Constant.ui.TAB_SETTINGS);
		mainTabs.addTab(Constant.ui.TAB_SETTINGS,
					settingsIcon,new SettingsPanel(),
					Constant.ui.TAB_SETTINGS_DESC);
		mainTabs.setMnemonicAt(1,KeyEvent.VK_2);

		mainContainer.add(mainTabs,BorderLayout.CENTER);
		
		
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setIconImage(Utils.createImageIcon(
				Constant.ui.TEXT_YOUTUBE).getImage());
		setSize(Constant.ui.WIDTH,Constant.ui.HEIGHT);
		Dimension screenSize=Toolkit.
				getDefaultToolkit().getScreenSize();
		int windowX=Math.max(0,
				(screenSize.width-Constant.ui.WIDTH)/2);
		int windowY=Math.max(0,
				(screenSize.height-Constant.ui.HEIGHT)/2);
		setLocation(windowX,windowY);
		
		setVisible(true);
	}
	
	
	
	public static void main(String args[]){
		new RemotePlayer(Constant.APP_NAME);
	}
}
